const STORAGE_USER_INFO_KEY = 'storage_user_info_key'
const STORAGE_SEARCH_HISTORY = 'storage_search_history'
export const getUserInfo = () => {
  const res = localStorage.getItem(STORAGE_USER_INFO_KEY)
  console.log(res)
  return res ? JSON.parse(res) : { token: '', userId: '' }
}
export const setUserInfo = (obj) => {
  localStorage.setItem(STORAGE_USER_INFO_KEY, JSON.stringify(obj))
}
export const removeUserInfo = (obj) => {
  localStorage.removeItem(STORAGE_USER_INFO_KEY)
}

export const getSearchHistory = () => {
  const res = localStorage.getItem(STORAGE_SEARCH_HISTORY)
  return res ? JSON.parse(res) : []
}

export const setSearchHistory = (history) => {
  if (history instanceof Array) {
    localStorage.setItem(STORAGE_SEARCH_HISTORY, JSON.stringify(history))
  }
}
